(function (vc) {
    vc.extends({
        data: {
            prestoreAccount2Info: {
                tel: '',
                ownerId: '',
                owners: [],
                amount: '',
                remark: '',
                receivedAmount: '',
                redepositAmount: '',
                totalAmount: '',
                acctType: '',
                primeRate: '',
                primeRates: [],
                amtTypes: [],
                amtType: '1001',
                feeConfigs:[],
                configId:'',
            }
        },
        _initMethod: function () {

        },
        _initEvent: function () {
            vc.on('prestoreAccount2', 'openAddModal', function () {
                $('#prestoreAccount2Model').modal('show');
            });
            vc.getDict('pay_fee_detail', "prime_rate", function (_data) {
                $that.prestoreAccount2Info.primeRates = _data;
            });
            vc.getDict('account_detail', "amt_type", function (_data) {
                $that.prestoreAccount2Info.amtTypes = _data;
            });
            vc.on('prestoreAccount2', 'openAddModalWithParams', function (_param) {
                vc.component.prestoreAccount2Info.acctType = _param.acctType;
                vc.component.prestoreAccount2Info.amount = _param.redepositAmount;
                vc.component.prestoreAccount2Info.redepositAmount = _param.redepositAmount;
                vc.component.prestoreAccount2Info.receivedAmount = _param.receivedAmount;
                vc.component.prestoreAccount2Info.totalAmount = (parseFloat(_param.receivedAmount) - parseFloat(_param.redepositAmount)).toFixed(2);
                vc.component.prestoreAccount2Info.ownerId = _param.objId;
                vc.component.prestoreAccount2Info.configId = _param.configId;
                $('#prestoreAccount2Model').modal('show');
                $that.initFeeConfig2();
                vc.getDict('pay_fee_detail', "prime_rate", function (_data) {
                    $that.prestoreAccount2Info.primeRates = _data;
                });
                vc.getDict('account_detail', "amt_type", function (_data) {
                    $that.prestoreAccount2Info.amtTypes = _data;
                });
            });
        },
        methods: {
            prestoreAccount2Validate() {
                return vc.validate.validate({
                    prestoreAccount2Info: vc.component.prestoreAccount2Info
                }, {
                    'prestoreAccount2Info.amount': [
                        {
                            limit: "required",
                            param: "",
                            errInfo: "金额不能为空"
                        },
                        {
                            limit: "money",
                            param: "",
                            errInfo: "金额格式错误"
                        },
                    ],
                    'prestoreAccount2Info.primeRate': [{
                        limit: "required",
                        param: "",
                        errInfo: "请选择支付方式"
                    }],'prestoreAccount2Info.amtType': [{
                        limit: "required",
                        param: "",
                        errInfo: "请选择账户变动类型"
                    }],'prestoreAccount2Info.configId': [{
                        limit: "required",
                        param: "",
                        errInfo: "请选择预存指定费项"
                    }],'prestoreAccount2Info.remark': [
                        {
                            limit: "maxLength",
                            param: "200",
                            errInfo: "备注长度不能超过200位"
                        }
                    ],
                });
            },
            savePrestoreAccount2Info: function () {
                if (!vc.component.prestoreAccount2Validate()) {
                    vc.toast(vc.validate.errInfo);
                    return;
                }
                vc.component.prestoreAccount2Info.communityId = vc.getCurrentCommunity().communityId;
                vc.http.apiPost(
                    '/account/ownerPrestoreAccount',
                    JSON.stringify(vc.component.prestoreAccount2Info),
                    {
                        emulateJSON: true
                    },
                    function (json, res) {
                        //vm.menus = vm.refreshMenuActive(JSON.parse(json),0);
                        let _json = JSON.parse(json);
                        if (_json.code == 0) {
                            //关闭model
                            $('#prestoreAccount2Model').modal('hide');
                            vc.component.clearPrestoreAccount2Info();
                            vc.emit('payFeeUserAccount', 'refresh', {});
                            vc.toast('预存成功');
                            return;
                        }
                        vc.toast(_json.msg);
                        // vc.component.prestoreAccount2Info.errorInfo = _json.msg;
                    },
                    function (errInfo, error) {
                        console.log('请求失败处理');
                        vc.component.prestoreAccount2Info.errorInfo = errInfo;
                    });
            },
            _computedAmount: function(){
                let amount = vc.component.prestoreAccount2Info.receivedAmount - vc.component.prestoreAccount2Info.totalAmount;
                amount = amount.toFixed(2);
                vc.component.prestoreAccount2Info.amount = amount < 0 ? 0 : amount;
            },
            clearPrestoreAccount2Info: function () {
                let _primeRates = $that.prestoreAccount2Info.primeRates;
                let _amtTypes = $that.prestoreAccount2Info.amtTypes;
                vc.component.prestoreAccount2Info = {
                    tel: '',
                    ownerId: '',
                    owners: [],
                    amount: '',
                    remark: '',
                    receivedAmount: '',
                    redepositAmount: '',
                    totalAmount: '',
                    primeRate: '',
                    primeRates: _primeRates,
                    amtType:_amtTypes,
                    amtType:''
                };
            },
            initFeeConfig2:function(){
                let param = {
                    params: {
                        page: 1,
                        row: 50,
                        communityId: vc.getCurrentCommunity().communityId,
                        ownerId: $that.prestoreAccount2Info.ownerId,
                    }
                };
                //发送get请求
                vc.http.apiGet('/fee.listFeeConfig',
                    param,
                    function (json) {
                        let _feeConfigInfo = JSON.parse(json);
                        vc.component.prestoreAccount2Info.feeConfigs = _feeConfigInfo.fees;
                    },
                    function () {
                        console.log('请求失败处理');
                        vc.component.prestoreAccount2Info.feeConfigs = [];s
                    }
                );
            }
        }
    });
})(window.vc);